﻿using System;

namespace PlugNT.Cms.Model
{
    public class UserInfo
    {

        private bool _islock = false;

        private System.Collections.Generic.Dictionary<string, object> dictab = null;


        public UserInfo()
        {
            dictab = new System.Collections.Generic.Dictionary<string, object>();
        }

        /// <summary>
        /// 得到字典类型的数据
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.Dictionary<string, object> GetDictionary()
        {
            return dictab;
        }

        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="objValue"></param>
        /// <returns></returns>
        public bool AddField(string fieldName, object objValue)
        {
            bool addFalg = false;
            if (!dictab.ContainsKey(fieldName))
            {
                dictab.Add(fieldName, objValue);
                addFalg = true;
            }
            return addFalg;
        }

        /// <summary>
        /// 设置字段
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="objValue"></param>
        /// <returns></returns>
        public bool SetField(string fieldName, object objValue)
        {
            bool setFalg = false;
            if (dictab.ContainsKey(fieldName))
            {
                dictab[fieldName] = objValue;
                setFalg = true;
            }
            return setFalg;
        }

        /// <summary>
        /// 得到字段字符串
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public string GetFieldString(string fieldName)
        {
            object objValue = GetField(fieldName);
            return (objValue == null) ? "" : objValue.ToString();
        }

        /// <summary>
        /// 得到字段
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public object GetField(string fieldName)
        {
            object objValue = null;
            dictab.TryGetValue(fieldName, out objValue);
            return objValue;
        }


        /// <summary>
        /// 是否锁定
        /// </summary>
        public bool islock
        {
            get { return _islock; }
        }

        /// <summary>
        /// 设置锁定
        /// </summary>
        public void SetLocked()
        {
            _islock = true;
        }
    }
}
